package com.ltu.controller;

import com.ltu.model.request.account.RoleMenuReq;
import com.ltu.domain.mp_entity.Role;
import com.ltu.model.request.account.RoleCommonReq;
import com.ltu.model.request.base.BaseIdReq;
import com.ltu.model.request.base.PageReqData;
import com.ltu.model.response.base.CodeDataResp;
import com.ltu.model.response.CodeResp;
import com.ltu.service.RoleMenuService;
import com.ltu.service.RoleService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import springfox.documentation.annotations.ApiIgnore;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import javax.validation.Valid;

/**
 * <p>
 *  管理页面：角色管理
 * </p>
 *
 * @author Vescky.L
 * @since 2019-10-23
 */
//@RestController
//@RequestMapping("/role")
//@Api(tags="Sys-角色模块")
@ApiIgnore
@RequiredArgsConstructor(onConstructor = @__(@Autowired))
public class RoleController {

    private final RoleService roleService;
    private final RoleMenuService roleMenuService;

    @ApiOperation(value="MP:新增、修改角色接口")
    @RequestMapping(value="/saveOrUpdate", method= RequestMethod.POST)
    public CodeResp saveOrUpdate(@Valid @RequestBody RoleCommonReq roleReq) {
        roleService.save(roleReq);
        return CodeDataResp.valueOfSuccess();
    }

    @ApiOperation(value="MP:删除角色接口")
    @RequestMapping(value="/delete", method=RequestMethod.POST)
    public CodeResp delete(@RequestBody RoleCommonReq baseIdReq) {
        return roleService.remove(baseIdReq);
    }

    @ApiOperation(value="MP:所有角色列表接口")
    @RequestMapping(value="/roleList", method=RequestMethod.POST)
    public CodeDataResp<Role> roleList(@RequestBody PageReqData page) {
       return roleService.getRoleList(page);
    }

    @ApiOperation(value="MP:修改角色菜单")
    @RequestMapping(value="/updateMenuListForRole", method= RequestMethod.POST)
    public CodeResp updateMenuListForRole(@Valid @RequestBody RoleMenuReq roleMenuReq) {
        roleMenuService.updateRoleMenu(roleMenuReq);
        return CodeDataResp.valueOfSuccess();
    }

    @ApiOperation(value="查询某角色菜单", notes = "id传入roleId")
    @RequestMapping(value="/getMenuListByRole", method= RequestMethod.POST)
    public CodeDataResp getMenuListByRole(@Valid @RequestBody BaseIdReq baseIdReq) {
        return roleMenuService.getRoleMenu(baseIdReq);
    }
}

